package main

import (
    "fmt"
    "ghost/myflag"
    "ghost/logic"
    "ghost/after"
    "ghost/cmd"
    "os/exec"
    "encoding/base64"
)

func main() {
    NewConfig, is, _ := myflag.NewFlag()
    if is == "v_false" {
        return
    } else if is == "vertify" {
        return
    }
    ierr := logic.CheckOldConn(NewConfig.Host. NewConfig.Port, NewConfig.DbName, NewConfig.TabName)
    if ierr != nil {
        return
    }
    TrunCmd := fmt.Sprintf("echo > /tmp/%s_ghost.log", NewConfig.TabName)
    _, err3 := exec.Command("bash", "-c", TrunCmd).Output()
    if err3 != nil {
        return
    }
    var (
        myuser = "mgr"
        mypasswd = "xxxx"
    )
    cmd.Cmd(NewConfig.Host. NewConfig.Port, myuser, string(mypasswd), NewConfig.DbName, NewConfig.TabName, NewConfig.Alter)
    if NewConfig.Columns == "none" || NewConfig.DType == "none" || NewConfig.DLen == "none" {
        // only for vertify
        fmt.Println("success")
    } else {
        // only for exec after check
        res, _, tp := after.CheckRes(NewConfig.Host. NewConfig.Port, NewConfig.DbName, NewConfig.TabName, NewConfig.Alter, NewConfig.Columns, NewConfig.DType, NewConfig.DLen)
        if res == "true" {
            fmt.Println("success")
        } else {
            fmt.Println("failed")
        }
    }
}